package edu.nf.bs.controller;

import com.github.pagehelper.PageInfo;
import edu.nf.bs.dao.OrderInfoMapper;
import edu.nf.bs.dao.impl.OrderInfoMapperImpl;
import edu.nf.bs.entity.DeliveryMan;
import edu.nf.bs.entity.OrderInfo;
import edu.nf.bs.service.OrderInfoService;
import edu.nf.bs.service.impl.OrderInfoServiceImpl;
import edu.nf.bs.vo.ResultVO;
import org.mvc.web.annotation.RequestMapping;
import org.mvc.web.servlet.View;
import org.mvc.web.view.JsonView;

import java.util.List;

public class OrderInfoContraller extends BaseContraller{
    /**
     * 计算今日收益
     * @return
     */
    @RequestMapping("/order/orderDatePrice")
    public View getFloat(){
        OrderInfoMapper mapper=new OrderInfoMapperImpl();
        OrderInfoServiceImpl service=new OrderInfoServiceImpl();
        service.setOrderInfoMapper(mapper);
        Double price = service.getPrice();
        ResultVO<Double> success = success(price);
        return new JsonView(success);
    }
    /**
     * 查看本月收益
     * @return
     */
    @RequestMapping("/order/orderMonthPrice")
    public View getPrice(){
        OrderInfoMapper mapper=new OrderInfoMapperImpl();
        OrderInfoServiceImpl service=new OrderInfoServiceImpl();
        service.setOrderInfoMapper(mapper);
        Double price = service.getPrices();
        ResultVO<Double> success = success(price);
        return new JsonView(success);
    }
    /**
     * 查询当天订单
     * @return
     */
    @RequestMapping("/order/daysOrderCount")
    public View getOrderCount(){
        OrderInfoMapper mapper=new OrderInfoMapperImpl();
        OrderInfoServiceImpl service=new OrderInfoServiceImpl();
        service.setOrderInfoMapper(mapper);
        Integer count = service.getOrderCount();
        ResultVO<Integer> success = success(count);
        return new JsonView(success);
    }

    /**
     * 查询一个月订单
     * @return
     */
    @RequestMapping("/order/daysOrdersCount")
    public View getOrderCounts(){
        OrderInfoMapper mapper=new OrderInfoMapperImpl();
        OrderInfoServiceImpl service=new OrderInfoServiceImpl();
        service.setOrderInfoMapper(mapper);
        Integer count = service.getOrderCounts();
        ResultVO<Integer> success = success(count);
        return new JsonView(success);
    }
    /**
     * 查询一个月订单
     * @return
     */
    @RequestMapping("/order/getOrderMax")
    public View getOrderMax(){
        OrderInfoMapper mapper=new OrderInfoMapperImpl();
        OrderInfoServiceImpl service=new OrderInfoServiceImpl();
        service.setOrderInfoMapper(mapper);
        DeliveryMan orderMax = service.getOrderMax();
        System.out.println(orderMax);
        ResultVO<DeliveryMan> success = success(orderMax);
        return new JsonView(success);
    }
    @RequestMapping("/orderInfo/list")
    public View listOrder(String orderId, Integer page, Integer limit) {
        OrderInfoMapper mapper=new OrderInfoMapperImpl();
        OrderInfoServiceImpl service = new OrderInfoServiceImpl();
        service.setOrderInfoMapper(mapper);
        System.out.println(page+"--------------"+limit);
        PageInfo<OrderInfo> pageInfo = service.listOrder(orderId, page, limit);
        ResultVO<List<OrderInfo>> vo = page(pageInfo);
        JsonView jsonView = new JsonView(vo);
        jsonView.setDateFormat("yyyy-MM-dd HH:mm:ss");
        return jsonView;
    }

    @RequestMapping("/orderInfo/getYearPrice")
    public View getYearPrice(){
        OrderInfoMapper mapper=new OrderInfoMapperImpl();
        OrderInfoServiceImpl service=new OrderInfoServiceImpl();
        service.setOrderInfoMapper(mapper);
        Double[] yearPrice = service.getYearPrice();
        ResultVO<Double[]> success = success(yearPrice);
        return new JsonView(success);
    }
    @RequestMapping("/order/userOrder")
    public View userOrder(String userId,Integer page,Integer limit){
        System.out.println(userId);
        OrderInfoMapper mapper=new OrderInfoMapperImpl();
        OrderInfoServiceImpl service = new OrderInfoServiceImpl();
        service.setOrderInfoMapper(mapper);
        System.out.println(userId);
        PageInfo<OrderInfo> orderInfoPageInfo = service.queryUserOrder(userId, page, limit);
        ResultVO<List<OrderInfo>> pageInfo = page(orderInfoPageInfo);
        System.out.println(orderInfoPageInfo.getList());
        JsonView jsonView = new JsonView(pageInfo);
        jsonView.setDateFormat("yyyy-MM-dd HH:mm:ss");
        return jsonView;
    }


}

